const mongoose = require('mongoose');
const {Schema, model} = mongoose;

const refereeSchema = new Schema({
        referee_name: { type: String },
        refereeId:     { type: Number, unique: true },
        refereesIdNew:     { type: Number },
        /**name:   { type: String },
        area:   { type: String },
        format: { type: String },
        type:   { type: String },
        category: { type: String },
        gender: { type: String },
        divisionLevel: { type: Number },*/
    },{
        toJSON: {
            transform: function(doc, ret, options) {
                delete ret._id;
                delete ret.__v;
                return ret;
            }
        }
    });

refereeSchema.static('findById', function(id) { return this.findOne({wyId:id}); });
refereeSchema.static('removeById', function(id) { return this.remove({id}); });
refereeSchema.static('upsert', function(id, refereeData) {
    return this.findOneAndUpdate({id}, refereeData, { new:true, upsert: true })
});

module.exports = model('referees', refereeSchema);